Skip to content

[ALL] Add the ability to override weapon slot and position, with very basic TF2 UI support #1202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

FlaminSarge
Copy link
Contributor

@FlaminSarge FlaminSarge commented Apr 16, 2025

Description

This PR adds the ability for vscript/mods/etc. to override the slot and position in which a weapon will appear in a player's weapon selection HUD for all games.
It does this by adding m_iSlot and m_iPosition as networked properties on CBaseCombatWeapon, which are initialized to the values previously returned by GetSlot() and GetPosition(). These two methods now return those properties (and have been moved to be inlined in the header file; this can be reverted if needed).
It also makes m_iSubType networked so that multiple weapons of the same class can be used by one player without any conflicts with SelectItem() behavior, if the vscript/mod so desires (lack of networking meant that overriding this during runtime would result in the client attempting to call SelectItem() on a subtype that may have desynced from server).

This PR also updates the TF2 weapon selection HUD to display the currently-selected weapon for the active slot if there are more than one weapon in that position, as well as updating the implementation for the TF2 Plus-type fastswitch HUD so that it can function even with multiple weapons in one slot. This includes a fix where slot5/slot6 inputs would cause the Plus-type HUD to function incorrectly.

If vscript/etc. do not touch these properties, all behavior remains the same as stock for all games.

Note that due to tf_weapon_builder's unique setup, it is not affected by these changes (yet).
tf_weapon_builder's slot/pos netprops are updated whenever SetSubType() is called on it but otherwise function as other weapons do.

Demonstration:
TF2: https://youtu.be/glJDdKqSIrU
HL2DM: https://youtu.be/XsAfBYtv54w

Includes the changes in #901

@FlaminSarge FlaminSarge changed the title Add the ability to override weapon slot and position, with very basic TF2 UI support [ALL] Add the ability to override weapon slot and position, with very basic TF2 UI support Apr 16, 2025
@FlaminSarge FlaminSarge marked this pull request as ready for review April 27, 2025 04:06
@FlaminSarge FlaminSarge force-pushed the bucket-prop branch 2 times, most recently from b07f4b2 to 1a65285 Compare April 27, 2025 04:25
@FlaminSarge
Copy link
Contributor Author

FlaminSarge commented Apr 27, 2025

The intent behind this PR is to provide base functionality with semi-functional UI for VScript to start working with in the base (live) game. Attributes were considered instead of properties, but then HL2 wouldn't gain the benefit of these changes and there would be undefined behavior if the attributes were added to player instead of to weapon.

Because GetSlot() and GetPosition() are strictly used for clientside weapon HUD selection, these new properties shouldn't break demos, as far as I can tell.

The followup change to fully implement a custom UI for extra weapon positions is a longer-term goal that may or may not be viable to merge into live game. I mainly plan to make it available for TF2 community mods to pull in, currently WIP at https://github.com/FlaminSarge/source-sdk-2013/tree/buckets, but if it's something that merges cleanly into base game, all the better.

@gidi30
Copy link

gidi30 commented May 20, 2025

This looks really good!
However it seems to be missing some code in CTFClientScoreBoardDialog and CTFHudPlayerClass to make it show the correct weapon model depending on whats equipped and not just the first weapon in the slot

@FlaminSarge
Copy link
Contributor Author

@gidi30 is that for the 3D player model in HUD? Good catch.

@FlaminSarge
Copy link
Contributor Author

FlaminSarge commented May 21, 2025

This looks really good! However it seems to be missing some code in CTFClientScoreBoardDialog and CTFHudPlayerClass to make it show the correct weapon model depending on whats equipped and not just the first weapon in the slot

On second thought, their usage of GetLoadoutSlot seems extremely deliberate for both cases:

int nItemSlot = ( pPlayer->IsAlive() && pPlayer->GetActiveTFWeapon() ) ? pPlayer->GetActiveTFWeapon()->GetAttributeContainer()->GetItem()->GetStaticData()->GetLoadoutSlot( nClass ) : LOADOUT_POSITION_PRIMARY;
...
	int nLoadoutSlot = pPlayer->GetActiveTFWeapon() ? pPlayer->GetActiveTFWeapon()->GetAttributeContainer()->GetItem()->GetStaticData()->GetLoadoutSlot( m_nClass ) : LOADOUT_POSITION_PRIMARY;

While I could replace this with just getting the active weapon, I'd like to find out the intent behind them sticking to loadout slots instead of just using the active weapon there...

I have put up a basic implementation at FlaminSarge/source-sdk-2013@bucket-prop...FlaminSarge:source-sdk-2013:bucket-playermodels but I do not think it is a very good implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants